<template>
  <el-container class="all">
    <el-header>
      <Header />
    </el-header>
    <el-main>
      <div class="left">
        <ul class="content">
          <li v-for="qa in qaList" :key="qa.id" class>
            <p class="title">
              <router-link :to="{name: 'User', params: { id: qa.question.userId} }" target="_blank">
                <el-avatar class="img" :src="qa.questionerAvatar" />
              </router-link>
              <span>
                <router-link :to="{name: 'QuestionDetail', params: { id: qa.question.id} }" target="_blank">
                  <a target="_blank" class="common-a">{{ qa.question.title }}</a>
                </router-link>
              </span>
              <router-link :to="{name: 'QuestionDetail', params: { id: qa.question.id} }" target="_blank">
                <strong class="answers">去回答</strong>
              </router-link>
            </p>
            <p class="text">{{ qa.question.content }}</p>
            <p class="label">
              <span>{{ parseTime(qa.question.createTime) }} · 回答{{ qa.answerCount }} · 有用 {{ qa.usefulCount }}</span>
            </p>
          </li>
        </ul>
        <el-pagination
          background
          layout="prev, pager, next"
          :total="total"
          :current-page="pageNum"
        />
      </div>
      <div class="right">
        <div class="up">
          <div class="contain">
            <p class="star">
              <a>{{ info.likeCount }}</a>
              <span>获赞数</span>
            </p>
            <p class="ans">
              <a>{{ info.replyCount }}</a>
              <span>回答数</span>
            </p>
            <p class="ques">
              <a>{{ info.collectCount }}</a>
              <span>提问数</span>
            </p>
          </div>
          <div class="btn">
            <el-button class="ques-b" @click="goto('/addQuestion')">我要提问</el-button>
            <el-button class="ans-b">我的问答</el-button>
          </div>
        </div>
      </div>
    </el-main>
    <el-footer><Footer /></el-footer>
  </el-container>
</template>

<script>
import Header from '../header/index.vue'
import Footer from '../foot/foot.vue'
import { getQuestionList } from '@/api/question'
import { getReplyLikeCollectCounts } from '@/api/user'
import { formatTime } from '@/utils/index'
export default {
  components: { Header, Footer },
  data() {
    return {
      qaList: [],
      info: Object(),
      total: Number(),
      pageNum: 1
    }
  },
  mounted() {
    this.getQuestionList()
    this.getReplyLikeCollectCounts()
  },
  methods: {
    getReplyLikeCollectCounts() {
      getReplyLikeCollectCounts({ userId: this.$store.state.user.id }).then(res => {
        this.info = res.data
        console.log(this.info)
      })
    },
    getQuestionList() {
      getQuestionList({ pageIndex: this.pageNum, pageSize: 10 }).then(res => {
        this.qaList = res.data.list
        this.total = res.data.total
        this.pageNum = res.data.pageNum
      })
    },
    parseTime(time) {
      return formatTime(new Date(time))
    },
    goto(path) {
      this.$router.push(path)
    }
  }
}
</script>

<style lang="scss" scoped>
// 分页
.el-pagination {
  text-align: center;
}
.all{
  display: flex;
  flex-direction: column;
  min-height: 100%;
}
.el-header {
  padding: 0;
}
.el-main {
  padding: 20px 0;
  background: #f3f4f5;
  display: flex;
  justify-content: center;
  overflow: auto;
}
.el-footer{
  padding: 0;
}
.left {
    width: 800px;
    float: left;
    margin-right: 20px;
}
.content {
  list-style-type: none;
}
.content li {
    margin-bottom: 20px;
    padding: 30px 30px 25px;
    background-color: #fff;
    border-radius: 10px;
}
.text {
    margin: 15px 0 15px 50px;
    font-size: 14px;
    line-height: 22px;
    color: #999;
    width: 656px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 4;
    overflow: hidden;
}
.content li span {
    font-size: 20px;
    color: #333;
    font-weight: 700;
}
.title {
    height: 30px;
    line-height: 30px;
}
.title strong {
    padding: 7px 17px;
    float: right;
    background-color: #0b8bff;
    border-radius: 8px;
    font-size: 14px;
    line-height: 14px;
    color: #fff;
    font-weight: 400;
    cursor: pointer;
}
.img {
    width: 30px;
    height: 30px;
    float: left;
    margin-right: 20px;
}
.common-a, .common-a:hover {
    text-decoration: none;
}
.label {
    margin-left: 50px;
}
.content li .label span {
    margin-right: 30px;
    font-size: 14px;
    line-height: 14px;
    color: #999;
    font-weight: 400;
}
.right {
  float: right;
  margin-top: 16px;
}
.up {
    background-color: #fff;
    border-radius: 10px;
    width: 380px;
    height: 250px;
    padding: 50px 30px;
    margin-bottom: 20px;
}
.contain {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    margin-bottom: 50px;
    p {
      -webkit-box-flex: 1;
      -ms-flex: 1;
      flex: 1;
      float: left;
      text-align: center;
      a {
        color: #0b8bff;
        font-size: 30px;
        line-height: 30px;
        text-decoration: none;
      }
      span {
        display: block;
        margin-top: 14px;
        font-size: 14px;
        color: #999;
        line-height: 14px;
      }
    }
}
.btn{
  display: flex;
  justify-content: center;
}
.el-button {
    width: 140px;
    height: 42px;
    background-color: #0b8bff;
    border-radius: 8px;
    border: 0;
    font-size: 16px!important;
    color: #fff;
    text-align: center;
    outline: 0;
}
</style>
